package com.leetcode_Onequestion;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;

public class leetcode_1488 {
    public static void main(String[] args) {

    }
    public static int[] aviodFload(int[] rains){
        int length = rains.length;
        int[] ans = new int[length];
        Map<Integer,Integer> full = new HashMap<>();
        TreeSet<Integer> ts = new TreeSet<>();
        for (int i = 0; i < rains.length; i++) {
            int cur = rains[i];
            if (cur > 0){
                ans[i] = -1;
                if (full.containsKey(cur)){
                    Integer fillDay = full.get(cur);
                    Integer emp = ts.ceiling(fillDay);
                    if (emp == null){
                        return new int[]{};
                    }else{
                        ans[emp] =cur;
                        ts.remove(emp);
                        full.put(cur,i);
                    }
                }else{
                    ans[i] = 1;
                    ts.add(i);
                }
            }
        }
        return ans;
    }

}
